package cn.edu.neusoft.food229.fragment;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.edu.neusoft.food229.R;
import cn.edu.neusoft.food229.adapter.CollectList2Adapter;
import cn.edu.neusoft.food229.adapter.CollectListAdapter;
import cn.edu.neusoft.food229.bean.Collect;
import cn.edu.neusoft.food229.listener.CollectListListener;
import cn.edu.neusoft.food229.model.CollectListModel;

import static android.content.Context.MODE_PRIVATE;

public class Fragment22 extends FragmentBase_229{
    private List<Collect> list;
    private RecyclerView recyclerView;
    private CollectList2Adapter adapter;
    private LinearLayoutManager layoutManager;
    private SharedPreferences sharedPreferences;//简单存储
    private String User_id;
    private Context context;
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context=context;
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment22,container,false);
    }
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        System.out.println("-----f21-----");
        sharedPreferences=context.getSharedPreferences("login",MODE_PRIVATE);
        User_id=sharedPreferences.getString("userid","");
        initRecyclerView(view);


    }

    private void initRecyclerView(View view) {
        recyclerView=view.findViewById(R.id.recyclerview22);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);//固定条目高度，提高性能
        CollectListModel model=new CollectListModel();
        model.collectList(User_id,1,new CollectListListener() {
            @Override
            public void onResponce(List<Collect> bean) {
                adapter=new CollectList2Adapter(context,bean);
                recyclerView.setAdapter(adapter);
            }

            @Override
            public void onFail(String msg) {

            }
        });
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setAdapter(adapter);

    }
}
